import { defHttp } from '@/utils/http/axios';
import { ErrorMessageMode } from '#/axios';
import { LoginReq, LoginRes, GetProfileRes, GetCaptchaRes, GetMenusRes } from './model/loginModel';

enum Api {
  Login = '/login',
  Logout = '/logout',
  GetCaptcha = '/captcha',
  GetProfile = '/profile',
  GetMenus = '/menus',
}

/**
 * @description: user login api
 */
export function apiLogin(params: LoginReq, mode: ErrorMessageMode = 'modal') {
  return defHttp.post<LoginRes>(
    {
      url: Api.Login,
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}

export function apiGetProfile() {
  return defHttp.get<GetProfileRes>({ url: Api.GetProfile }, { errorMessageMode: 'none' });
}

export function apiGetMenus() {
  return defHttp.get<GetMenusRes>({ url: Api.GetMenus }, { errorMessageMode: 'none' });
}

export function apiDoLogout() {
  return defHttp.post({ url: Api.Logout });
}

export function apiGetCaptcha() {
  return defHttp.get<GetCaptchaRes>({ url: Api.GetCaptcha });
}
